<%@ page language="java" import="java.util.*,com.xiaobin.system.util.*" pageEncoding="UTF-8"%>
<%@ include file="/base/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>${systemOption.systemTitle}</title>
    <%@ include file="/base/head.jsp"%>
    <script type="text/javascript" src="${ctx}/ueditor/third-party/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx}/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${ctx}/ueditor/lang/zh-cn/zh-cn.js"></script>  
    <script type="text/javascript" charset="UTF-8">
var dataUser;
var dataUserCC;
var resciveId='';
var rescive='';
$(function(){
	$('#aa').tree ({
		animate:true,
		checkbox:'true'
	});
 	$('#zdyyh').tree ({
		animate:true,
		checkbox:'true'
	}); 
});
function loadUser(){
	if(dataUser == null ) {
		$.ajax({
			async: false,
		    type : "post",
		    url : '${ctx}/msg/listTree.action',
		    success : function(data) {
		    		
		    	$('#aa').tree('loadData',data);	
		      
		       	dataUser = data;  	 
		    }
		});
	}
}
function loadUserCC(){
	if(dataUserCC == null ) {
		$.ajax({
			async: false,
		    type : "post",
		    url : '${ctx}/msg/listGsLinkManByDS.action',
		    success : function(data) {
		    	$('#zdyyh').tree('loadData',data);	
		       	dataUserCC = data;  
		       
		    }
		});
	}
}
function showTxl(){
   	resciveId='';
   	rescive='';
   	loadUser();
   	//loadUserCC();
   	$('#txlId').show();
   	$('#txlId').dialog({
   		title:'通讯录',
        modal:true,
        closable:false,
        buttons: [{
			text:'确定',
			iconCls:'icon-ok',
			handler:function(){
				$('#r_name').val('');
		        var  pa = $('#aa').tree('getChecked');//获取所有选中公司用户
		        var  paCC = $('#zdyyh').tree('getChecked');//获取所有选中邮箱用户
		        if(pa == '' && paBB =='' && paCC==''){
		        	$.messager.alert('友情提示','请选择接收人!','error');	
		        	return;
		        }
				for(var i = 0;i<pa.length;i++){
				 	if(isNaN(pa[i].id)){
					 	if(resciveId !=''){
					 		resciveId +=",";
					 		rescive +=",";
					 	
					 	}
				 		resciveId += pa[i].id;
				 		rescive += pa[i].text;
				 	}
				 }
				 for(var i = 0;i<paCC.length;i++){
				 	if(isNaN(paCC[i].id)){
					 	if(resciveId !=''){
					 		resciveId +=",";
					 		rescive +=",";
					 	}
				 		resciveId += paCC[i].id;//username
				 		rescive += paCC[i].text;//name
				 	}
				 }
				 var subStr = '';
				 if(resciveId.length>3000000){
				 	subStr = resciveId.substring(0,296)+"..";
				 }else{
				 	subStr = resciveId;
				 }
				 $('#r_name').val(subStr);
				 $('#rid').val(resciveId);
				 $('#txlId').dialog('close');
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
			 	$('#txlId').dialog('close');
			 	
			 	clearSelectedTree('#aa');
			 	clearSelectedTree('#zdyyh');
			 	//选中所选节点
			 	var resId = $('#rid').val();
			 	var allCheck = resId.split(',');
			 	for(var i = 0;i<allCheck.length;i++){
			 		var node = $('#aa').tree('find',allCheck[i]);
			 		if(null != node && node !=''){//如果名称在树上，则选中
			 			$('#aa').tree('check',node.target);
			 		}
			 		var node = $('#zdyyh').tree('find',allCheck[i]);
			 		if(null != node && node !=''){//如果名称在树上，则选中
			 			$('#zdyyh').tree('check',node.target);
			 		}
	  			}
			}
		}]
   	 });
   }
    /**
 	        制空被选中树的节点
 	*/
 function clearSelectedTree(tree){
 	var  pa = $(tree).tree('getChecked');//获取所有选中公司用户
	if (pa) {
		for(var i = 0;i<pa.length;i++){
			$(tree).tree('uncheck', pa[i].target);
	  }
    }
 }
function send(){
	var r_name = $('#r_name').val();
	if(r_name!=""){
		$.messager.progress({msg:'发送中，请稍候...', text:''});
		$('#sendForm').form('submit', {
			onSubmit: function(){
				var isValid = $(this).form('validate');
				if (!isValid){
					$.messager.progress('close');// 当form不合法的时候隐藏工具条
				}
					return isValid;	// 返回false将停止form提交 
			},
			success : function(data) {
				if (data) {
					$.messager.alert('友情提示', '发送成功', 'info');
				} else {
					$.messager.alert('友情提示', '发送失败', 'error');
				}
				$.messager.progress('close'); 
				document.getElementById("sendForm").reset();
				ue.setContent(''); 
			}
		});
	}else{
		$.messager.alert('友情提示', '请选择接收人', 'error');
	}
}
	</script>
	<style type="text/css">
		.send tr td{padding-bottom:5px; padding-top:5px; height:auto;}
		.send tr td a:link,a:visited{text-decoration:underline;color:#005590;}
		.send tr td  a:hover {text-decoration:none; }
		.label{ text-align:center;}
	</style>
  </head>
  
  <body style="margin:0px;">
      <!-- 主窗口 -->  	 
  	  <form name="sendForm" id="sendForm" method="post" action="${ctx }/msg/save.action">
			<table class="send" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td colspan="2" class="toolDiv">
						<a href="javascript:void(0)" onclick="send();" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" style="float:left;">发送</a><div class="datagrid-btn-separator"> </div>
					</td>
				</tr>
				<tr> 
					<td width="100px;" align="center" class="label">
						<a href="#" onclick="showTxl()" style="color:blue;text-decoration:underline;width: 30px" >接收人</a>
					</td>
					<td>
					
						<textarea name="RName" cols="2" readonly="readonly" style="overflow-y:hidden;height:20px;width:99%;" onpropertychange="this.style.height=this.scrollHeight+'px';" 
			  				oninput="this.style.height=24+'px';this.style.height=this.scrollHeight+'px';"  id="r_name"></textarea>
				
					    <input id="rid"  type="hidden" name="rid" />
					</td>
				</tr>
				<tr>
					<td align="center" class="label">
						主题
					</td>
					<td>
						<input id="subject" class="easyui-validatebox" name="subject" type="text" missingMessage="请填写消息主题" style="width:99%">
					</td>
				</tr>
				<tr>
					<td align="center" class="label">
						内容
					</td>
					<td>
						<div>
   	  	<script id="editor" name="content" type="text/plain" style="height:300px;width:90%;word-break:break-all;">${content}</script>					
        <script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
   
   </script>
						</div>
					</td>
				</tr>
			</table>
		</form>
<div data-options="title:'通讯录'" style="width:450px;display: none" id="txlId">
	<div id="rr" class="easyui-tabs" style="width: 240px; height:300px; float:left;" data-options="fit:true,border:false">
		<div title="公司用户">  
			<ul id="aa" class="easyui-tree"></ul>
		</div>
		<div title="我的分组" style="height: 400px;">  
			<ul id="zdyyh" class="easyui-tree"></ul>
		</div>
	</div>
</div>
  </body>
</html>
